package com.lynn.common.utils;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

public class ActivityUtil {

    //通过一个List来暂存活动
    private static List<Activity> activities = new ArrayList<>();

    public static void addActivity(Activity activity) {
        activities.add(activity);
    }

    public static void removeActivity(Activity activity) {
        activities.remove(activity);
    }

    /**
     * 结束所有的Activity
     */
    public static void finishAll() {
        for (Activity activity : activities) {
            try {
                if (activity != null && !activity.isFinishing()) {
                    activity.finish();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 退出应用程序
     */
    public static void exitApp() {
        finishAll();
        System.exit(0);
    }
}
